import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 组织机构标记枚举 */
export enum OrganizationFlagEnum {
  /** 当前组织机构标识 */
  CurrentToken = '@CurrentOrganizationId',
  /** 当前及子级组织机构标识 */
  CurrentChildrenToken = '@CurrentChildrenOrganizationId',
  /** 当前及父级组织机构标识 */
  CurrentParentToken = '@CurrentParentOrganizationId',
  /** 当前及父级子级组织机构标识 */
  CurrentParentChildrenToken = '@CurrentParentChildrenOrganizationId',
  /** 子级组织机构标识 */
  ChildrenToken = '@ChildrenOrganizationId',
  /** 父级组织机构标识 */
  ParentToken = '@ParentOrganizationId',
  /** 父级子级组织机构标识 */
  ParentChildrenToken = '@ParentChildrenOrganizationId',
}

/** 组织机构标记实体 */
export class OrganizationFlagEntity {
  /** 组织机构标记 */
  OrganizationFlag: OrganizationFlagEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(organizationFlag: OrganizationFlagEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.OrganizationFlag = organizationFlag;
    this.Color = color;
    switch (organizationFlag) {
      case OrganizationFlagEnum.CurrentToken:
        // this.Display = '@当前组织';
        this.Display = `@${t('enum.organizationFlag.currentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case OrganizationFlagEnum.CurrentChildrenToken:
        // this.Display = '@当前及子级组织';
        this.Display = `@${t('enum.organizationFlag.currentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Cyan;
        break;
      case OrganizationFlagEnum.CurrentParentToken:
        // this.Display = '@当前及父级组织';
        this.Display = `@${t('enum.organizationFlag.currentParentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case OrganizationFlagEnum.CurrentParentChildrenToken:
        // this.Display = '@当前及父级子级组织';
        this.Display = `@${t('enum.organizationFlag.currentParentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Geekblue;
        break;
      case OrganizationFlagEnum.ChildrenToken:
        // this.Display = '@子级组织';
        this.Display = `@${t('enum.organizationFlag.childrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
      case OrganizationFlagEnum.ParentToken:
        // this.Display = '@父级组织';
        this.Display = `@${t('enum.organizationFlag.parentToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Pink;
        break;
      case OrganizationFlagEnum.ParentChildrenToken:
        // this.Display = '@父级子级组织';
        this.Display = `@${t('enum.organizationFlag.parentChildrenToken')}`;
        this.Color = this.Color ? this.Color : PresetColorEnum.Red;
        break;
    }
  }
}

//#region 获取组织机构标记枚举架构
/**
 * 获取组织机构标记枚举架构
 */
export function getOrganizationFlagEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: OrganizationFlagEntity[] = [
    new OrganizationFlagEntity(OrganizationFlagEnum.CurrentToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.CurrentChildrenToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.CurrentParentToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.CurrentParentChildrenToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.ChildrenToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.ParentToken),
    new OrganizationFlagEntity(OrganizationFlagEnum.ParentChildrenToken),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.OrganizationFlag as string,
      label: item.Display,
      value: item.OrganizationFlag as string,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
